﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Xml.Linq;
using System.Web.UI.WebControls;

public partial class service_responseToSettingSearchEngine : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string dataFromClient = Server.UrlDecode(Request.Form.ToString());
        if (Request.QueryString["act"] == "get")
        {
            if (Request.QueryString["username"] == null)
            {
                Response.Write("searchEngine=baidu");
            }
            user userInstance = new user(HttpContext.Current.Request.PhysicalApplicationPath + "userdata//" + Request.QueryString["username"] + @"\user.xml");//读取user信息
            if (userInstance.SearchEngine == "")//检验密码
            {
                Response.Write("searchEngine=baidu");
            }
            else
            {
                Response.Write("searchEngine=" + userInstance.SearchEngine);
            }
        }
        if (Request.QueryString["act"] == "set")
        {
            if (Request.QueryString["username"] == null || Request.QueryString["password"] == null || Request.QueryString["searchEngine"] == null)
            {
                Response.Write("result=failed");
            }
            else
            {
                string currentDir = MapPath("") + @"\userdata\" + Request.QueryString["username"] + @"\";
                user userInstance = new user(currentDir + @"user.xml");
                userInstance.SearchEngine = Request.QueryString["searchEngine"];//save the check code in the xml file.
                userInstance.setAllValue();
                userInstance.saveToFile(currentDir + @"user.xml");
            }
        }

    }
}